<template>
  <div>
 <el-table
    :data="getMenuData"
    border
    :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    row-key='id'

    style="width: 100%">
    <el-table-column
      prop="id"
      label="菜单编号"
      width="60">
    </el-table-column>
    <el-table-column
      prop="title"
      label="菜单名称"
      width="180">
    </el-table-column>
    <el-table-column
      label="上级菜单"
        width="50"
        prop='pid'
      >
    </el-table-column>

        <el-table-column
      label="菜单图标"
        width="140"
      >
<template slot-scope="item">
        <div>
         <i :class="item.row.icon"></i>
        </div>
      </template>

    </el-table-column>
        <el-table-column
      label="菜单地址"
        width="180"
        prop="url"
      >
    </el-table-column>
        <el-table-column
      label="状态"
        width="180"
      >
 <template slot-scope="item">
        <div>
          {{item.row.status==1?'启用':'禁用'}}
        </div>
      </template>

    </el-table-column>
        <el-table-column
      label="操作"
        width="180"
      >

       <template slot-scope="item">
        <div>
  <el-button plain  size="mini" @click='edit(item.row.id)'>编辑</el-button>
 <el-button plain  size="mini" @click="remove(item.row.id)">删除</el-button>

        </div>
      </template>

    </el-table-column>
  </el-table>

  </div>
</template>

<script>
import { mapActions, mapGetters } from 'vuex'
import { menudelete } from '../../../api/api.js'
export default {
  data () {
    return {
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }]
    }
  },
  mounted () {
    this.getMeulist()
  },
  computed: {
    ...mapGetters('menu', ['getMenuData'])
  },

  methods: {
    ...mapActions('menu', ['getMeulist']),
    // 删除接口
    remove (id) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        menudelete({ id }).then(res => {
          if (res.code === 200) {
            this.$message.success(res.msg)
            this.getMeulist()
          } else {
            this.$message.error(res.msg)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    edit (id) {
      this.$emit('edit', id)
    }
  }
}
</script>

<style>

</style>
